<template>
  <div id="app">
    <h2>测试题</h2>
    <count 
    v-for="(item, index) in math" 
    :obj="item"
    :index="index"
    @complete="complete">
    </count>
    <div>
      <flag v-for="item in math" :obj="item"></flag>
    </div>
  </div>
</template>

<script>
import Count from "components/count/Count";
import Flag from "components/count/Flag";

export default {
  data() {
    return {
      arr: []
    }
  },
  components: {
    Count,
    Flag,
  },
  computed: {
    math() {
       for (let i = 0; i < 5; i++) {
        const num1 = parseInt(Math.random() * 10);
        const num2 = parseInt(Math.random() * 10);
        const state = false
        this.arr.push({
          num1,
          num2,
          state
        });
      }
      return this.arr
    },
  },
  methods: {
    complete(index, isOK) {
      this.math[index].state = isOK
    }
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>
